/*
* webide for education
*/
package com.webide.account.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.webide.core.entity.BeanRet;
import com.webide.core.entity.Page;
import com.webide.core.tools.redis.RedisUtils;
import com.webide.account.entity.Account;
import com.webide.account.service.AccountSV;

/**
* 账户 控制器
*
* @author helixin
*/
@RestController
@RequestMapping("/account")
@Slf4j
@Api(value = "账户控制器", description = "账户控制器")
public class AccountCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private AccountSV accountSV;

    /**
    * 查询Account一个详情信息
    * @param id 
    * @param code 账户编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Account一个详情信息", notes = "查询Account一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "账户编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id,java.lang.String code) {
        if(id==null){
        return null;
        }
        if(code==null){
        return null;
        }
        Account accountObj = accountSV.load(id,code);
        log.info(JSON.toJSONString(accountObj));
        return BeanRet.create(true, "查询成功", accountObj);
    }


    /**
    * 根据条件id查询Account一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Account一个详情信息", notes = "查询Account一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        Account accountObj = accountSV.loadById(id);
        log.info(JSON.toJSONString(accountObj));
        return BeanRet.create(true, "查询成功", accountObj);
    }
    /**
    * 根据条件code查询Account一个详情信息
    *
    * @param code 账户编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Account一个详情信息", notes = "查询Account一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "账户编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if(code==null){
           return null;
        }
        Account accountObj = accountSV.loadByCode(code);
        log.info(JSON.toJSONString(accountObj));
        return BeanRet.create(true, "查询成功", accountObj);
    }


    /**
    * 查询Account信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Account信息集合", notes = "查询Account信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list( @ApiIgnore Account accountObj,Integer curPage,Integer pageSize) {
        Page<Account> page=new Page<Account>(pageSize,curPage);
        List<Account> accountObjs = accountSV.list(accountObj,page.genRowStart(),page.getPageSize());
        page.setVoList(accountObjs);
        int total = accountSV.count(accountObj);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, "查询成功", page);

    }


    /**
    * 查询Account信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Account信息集合", notes = "查询Account信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "账户编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id,java.lang.String code,Integer curPage,Integer pageSize) {
        Page<Account> page=new Page<Account>(pageSize,curPage);
        List<Account> accountObjs = accountSV.list(id,code, page.genRowStart(),page.getPageSize());
        page.setVoList(accountObjs);
        int total = accountSV.count(id,code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, "查询成功", page);
    }

    /**
    * 统计Account信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计Account信息数量根据主键", notes = " 统计Account信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "账户编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String code) {
        return accountSV.count(id,code);
    }

    /**
    * 统计Account信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计Account信息数量", notes = "统计Account信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "账户编码", paramType = "query"),
    @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
    @ApiImplicitParam(name = "password", value = "密码", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore Account accountObj) {
        if(accountObj==null){
            return accountSV.count(new HashMap());
        }else{
            return accountSV.count(accountObj);
        }
    }



    /**
    * 创建Account
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建Account", notes = "创建Account")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
    @ApiImplicitParam(name = "password", value = "密码", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore Account accountObj) {
        accountSV.save(accountObj);
        return BeanRet.create(true, "创建成功", accountObj);
    }


    /**
    * 修改Account
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改Account", notes = "修改Account")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "账户编码", paramType = "query"),
        @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
        @ApiImplicitParam(name = "password", value = "密码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore Account accountObj) {
        accountSV.modify(accountObj);
         return BeanRet.create(true, "修改成功", accountObj);
    }

    /**
    * 删除Account
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除Account", notes = "删除Account")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "账户编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        accountSV.delete(id,code);
        return BeanRet.create(true, "删除Account成功");
    }

}
